﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SonCa.SocialNetwork.Profiles.IPresenters;
using Core.DataAccess;
using System.ComponentModel.Composition;
using Core.Interfaces;
using SonCa.SocialNetwork.Profiles.Presenters;
using Core.Common;
using SonCa.SocialNetwork.Web.Personals.Presenters;

namespace SonCa.SocialNetwork.Web.Personals
{
    public partial class PersonalPage : System.Web.UI.Page, IUploadAvatar
    {
        private UploadAvatarPresenter _presenter;
        private PersonalFriendPresenter _friendPresenter;

        [Import]
        private IUserSession _userSession;

        protected void Page_Load(object sender, EventArgs e)
        {
            MEFManager.Compose(this);
            if (!string.IsNullOrEmpty(Request.QueryString["otherAccountID"]))
                _userSession.OtherAccountID = Convert.ToInt32(Request.QueryString["otherAccountID"].ToString());
            _presenter = new UploadAvatarPresenter();
            _presenter.Init(this);            
        }

        public void ShowMessage(string Message)
        {
            
        }

        public void ShowCropPanel()
        {
            
        }

        public void ShowApprovePanel()
        {
            
        }

        public void ShowUploadPanel()
        {
            
        }

        public void ShowAvatar(int accountID)
        {
            
        }

        public void ShowInfo(Account account, WorkPlace workPlace)
        {
            if (account != null)
            {
                string level = _presenter.GetLevelByLevelID(Convert.ToInt32(account.LevelID));
                imgLevel_profile.ImageUrl = "../img/" + level;
                lblScore_profile.Text = account.Score.ToString();

                lblUserName_profile.Text = account.LastName + " " + account.MidName + " " + account.FirstName;
                lblBirth_profile.Text = Convert.ToDateTime(account.BirthDate).ToShortDateString();
                imgAvatar_profile.ImageUrl = "~/Images/ProfileAvatar/ProfileImage.aspx?AccountID=" + account.AccountID.ToString();

                if (_userSession != null && _userSession.OtherAccountID > 0)
                {
                    hdfOtherAccountID.Value = _userSession.OtherAccountID.ToString();
                    int check = _presenter.CheckAccountByAccountID();
                    if (check == -1)
                        btnAddFriend_profile.Visible = false;
                    else if (check == 0)
                    {
                        btnAddFriend_profile.Attributes.Add("src", "~/img/requestsended.png");
                        btnAddFriend_profile.Attributes.Add("alt", "Đã gửi yêu cầu kết bạn.");
                        btnAddFriend_profile.Attributes.Remove("style");
                        btnAddFriend_profile.Attributes.Remove("onclick");
                    }
                    else if (check == 1)
                        btnAddFriend_profile.Visible = true;
                }
                else
                    btnAddFriend_profile.Visible = false;
            }            
        }

        public void CloseDialog()
        {
            
        }
    }
}